<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{



    protected function _initVista()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'My_View_Helper');
        $view->headTitle('Viriathus')->setSeparator(' / ');

        $date = new Zend_Date();
        $view->fecha_footer =Sgit_Filter_DateDbToLocalize::filter($date,Zend_Date::DATES);
    }

    protected function _initSession()
    {
        Zend_Session::start();
        $sgit_session = new Zend_Session_Namespace('sgit');
        Zend_Registry::set('sgit_session', $sgit_session);
    }
    
    
    


    protected function _initCache()
    {
        //cache
        $frontendOptions = array('lifetime' => 36000, // 1 hora
            'automatic_serialization' => true);
        $backendOptions = array('cache_dir' => APPLICATION_PATH . '/tmp/');

        // getting a Zend_Cache_Core object
        $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
        
        
        Zend_Registry::set('cache', $cache);
        return $cache;

    }
/*
    protected function _initCurrency()
    {
        
        $currency=new Zend_Currency(
            array(
                'locale'=>'es',
                'position' => Zend_Currency::RIGHT,
                'precision'=>0
            )
        );
        
        $currency2=new Zend_Currency(
            array(
                'locale'=>'es',
                'position' => Zend_Currency::RIGHT,
                'precision'=>2
            )
        );
        
        $cache = $this->getResource('Cache');
        
        Zend_Registry::set('Zend_Currency',$currency );
        Zend_Registry::set('Zend_Currency2',$currency2 );
        Zend_Currency::setCache($cache);
    }
*/


    public function _initLocale()
    {
        return true;
 
        $localeValue = 'es';

        define('LOCALE',$localeValue);
        
        if($localeValue=='es') $locale = new Zend_Locale('es_ES');
        if($localeValue=='en') $locale = new Zend_Locale('en_GB');
        
        Zend_Registry::set('Zend_Locale', $locale);
        
        $this->bootstrap('db');

        $cache = $this->getResource('Cache');
        Zend_Translate::setCache($cache);

         
         //quiza haya otra forma de cachear el zend_transalte en lugar de la db 
        if( ($content=$cache->load('Translate_Array_Options_'.$localeValue)) === false ) {
            if($localeValue!='es'){
                $dbAdapter = $this->getResource('db');
                $select = $dbAdapter->select()->from('translation',array('es',$localeValue));
                $translateTable = $dbAdapter->fetchAll($select);
                foreach($translateTable as $v){
                    $content[$v['es']]=$v[$localeValue];
                }
                $cache->save($content, 'Translate_Array_Options_'.$localeValue);
            }
        }


        $translate = new Zend_Translate(
            array(
                'adapter' => 'array',
                'content' => $content,
                'locale'  => $localeValue
            )
        );



        Zend_Form::setDefaultTranslator($translate);
        Zend_Registry::set('Zend_Translate', $translate);

    }




    protected function _initPlugin()
    {
        $this->bootstrap('db');
        $db = $this->getResource('db');

        Zend_Registry::set("database", $db);
        
        $cache = $this->getResource('Cache');

        Zend_Controller_Action_HelperBroker::addHelper(new Sgit_Controller_Action_Helper_Profiler($db,$cache));


    }

    protected function _initSyslog()
    {
        //Logger db
        $this->bootstrap('db');
        $dbAdapter = $this->getResource('db');


        $columnMapping = array('level' => 'priorityName', 'message' => 'message', 'eventTime' => 'timestamp');

        $writer = new Zend_Log_Writer_Db($dbAdapter, 'logger', $columnMapping);
        $loggerDB = new Zend_Log($writer);
        Zend_Registry::set('loggerDB', $loggerDB);

        //Logger firebug
        $writer = new Zend_Log_Writer_Firebug();
        $loggerFirebug = new Zend_Log($writer);
        Zend_Registry::set('loggerFirebug', $loggerFirebug);

        //Logger texto
        $file = date('Ymd') . 'log.txt';
        $writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/logs/' . $file);
        $loggerTxt = new Zend_Log($writer);
        Zend_Registry::set('loggerTxt', $loggerTxt);

    }


    /*
    function _initErrorCatcher() {
    // Sgit_Error_Handler::set();
    } 
    */

    /*
    protected function _initRequest()
    {
        // Ensure front controller instance is present, and fetch it
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');
    
        // Initialize the request object
        $request = new Zend_Controller_Request_Http();
        $request->getparams();
        
        
        Zend_Debug::dump($request);
        // Add it to the front controller
       // $front->setRequest($request);
        // Bootstrap will store this value in the 'request' key of its container
       // return $request;
    }
    */
    

}
